
{extend name='public/base' /}
{block name="css"}

{/block}
{block name="content"}

<div class="ibox xiaoshi">
    <div class="ibox-content">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form class="form-inline" id="form">
                    <div class="select-list">
                        <ul>
                            {:li_input('权限名称','title')}

                            {:li_select(['1'=>'停用','2'=>'正常'],'状态','status')}

                            {:li_time('时间范围')}

                            {:li_search()}

                        </ul>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>



<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-content">
                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success  btn-rounded {:node('AuthGroup/addGroups')}" onclick="$.form.add()">
                        <i class="fa fa-plus"></i> 新增
                    </a>
                    <a class="btn btn-primary btn-rounded single " onclick="$.form.edit()">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-danger btn-rounded multiple " onclick="$.form.removeAll()">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-warning btn-rounded" onclick="$.table.exportExcel()">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <div class="table-striped">
                    <table id="bootstrap-table" ></table>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"} <!--js处理区-->

<script>
    $(function() {
        var options = {
            url: "{:url('index')}",
            deleteUrl:  "{:url('del')}?id={id}", //删除链接
            exportUrl:  "{:url('export')}",  //导出
            updateUrl: "{:url('addGroups')}?id={id}", //编辑
            addUrl:    "{:url('addGroups')}?id={id}", //添加
            detailUrl:  "/detailUrl",    //详细
            sortName: "id",
            sortOrder: "asc",
            modalName: "权限管理组",
            onEditableSave: onEditableSave, //行内编辑
            onDblClickRow:onDblClickRow, //双击行编辑
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID'
                },
                {
                    field : 'title_show',
                    title : '名称',
                    editable : {
                        type : 'text',
                        title : '名称',
                        emptytext : "【名称】为空",
                        validate : function(value) {
                            if (value.length > 30) {
                                return '名称不能超过30个字符';
                            }
                            if (value.length == 0) {
                                return '名称不能为空';
                            }
                        }
                    }
                },
                {
                    field: 'status',
                    title: '用户状态',
                    align: 'center',
                    editable : {
                        type : 'select',
                        title : '状态',
                        source : [{
                            value : 1,
                            text : '正常'
                        }, {
                            value : 0,
                            text : '禁用'
                        }]
                    }
                },
                {
                    field: 'rules',
                    title: '授权节点'
                },
                {
                    field: 'create_time',
                    title: '添加时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                          return edit_del(row);
                    }

                }]
        };
        $.table.init(options);
    });

    function edit_del(row) {
        if(row.id==1){
            return ' 超级管理不允许编辑';
        }else {
            var actions = [];
            actions.push('<a class="btn btn-primary btn-xs {:node(\'AuthGroup/userGroup\')}" data-original-title="授权人员" data-toggle="tooltip" onclick="quan(\'' + row.id + '\')"><i class="fa fa-key"></i></a>');
            actions.push('<a class="btn btn-xs btn-success  {:node(\'AuthGroup/addGroups\')}" data-original-title="编辑" data-toggle="tooltip" onclick="$.form.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a>');
            actions.push('<a class="btn btn-danger btn-xs {:node(\'AuthGroup/del\')}" data-original-title="删除" data-toggle="tooltip" onclick="$.form.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i></a>');
            return actions;
        }
    }

    function quan(id) {
       var url="{:url('userGroup')}?id="+id;
       $.form.OpenForm('授权',url,'','',true);
    }

    //双击行编辑
    function onDblClickRow(row) {
       // alert(JSON.stringify(row))
        if (row.id==1){
            $.models.toastr_warning("超级管理权限不允许编辑");
        }else {
            $.form.edit(row.id);
        }
    }
    function onEditableSave (field, row, oldValue) {
        $.form.Change_status("{:url('common/changeStatus')}","auth_group",row.id,field,row[field]);
    }
</script>

{/block}
